package com.jzg.jcptadmin.ui;

import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.LocalBroadcastManager;
import android.text.Editable;
import android.text.Selection;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.bigkoo.convenientbanner.listener.OnItemClickListener;
import com.google.gson.Gson;
import com.jakewharton.rxbinding.view.RxView;
import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.Utils.CommonUtil;
import com.jzg.jcptadmin.Utils.InputLowerToUpper;
import com.jzg.jcptadmin.Utils.MD5Utils;
import com.jzg.jcptadmin.Utils.MyNumberKeyListener;
import com.jzg.jcptadmin.Utils.MyToast;
import com.jzg.jcptadmin.Utils.ScreenUtils;
import com.jzg.jcptadmin.Utils.StringUtils;
import com.jzg.jcptadmin.adpter.FragmentTabAdapter;
import com.jzg.jcptadmin.app.AppManager;
import com.jzg.jcptadmin.base.BaseActivity;
import com.jzg.jcptadmin.constant.Constant;
import com.jzg.jcptadmin.data.DataManager;
import com.jzg.jcptadmin.data.local.ACache;
import com.jzg.jcptadmin.data.local.LocalData;
import com.jzg.jcptadmin.data.vo.Canpei;
import com.jzg.jcptadmin.data.vo.CarDetails;
import com.jzg.jcptadmin.data.vo.CheckVinBean;
import com.jzg.jcptadmin.data.vo.City;
import com.jzg.jcptadmin.data.vo.Make;
import com.jzg.jcptadmin.data.vo.Province;
import com.jzg.jcptadmin.data.vo.RepairBean;
import com.jzg.jcptadmin.data.vo.Style;
import com.jzg.jcptadmin.data.vo.SuccessValuationData;
import com.jzg.jcptadmin.data.vo.UpDataResult;
import com.jzg.jcptadmin.presenter.CheckVinPrsenter;
import com.jzg.jcptadmin.presenter.OperationEvaluationPresenter;
import com.jzg.jcptadmin.ui.fragment.HistoricalPriceFragment;
import com.jzg.jcptadmin.ui.fragment.SpotPriceFragment;
import com.jzg.jcptadmin.view.MarqueeText;
import com.jzg.jcptadmin.view.SelectDateActivity;
import com.jzg.jcptadmin.view.SheetTimeAty;
import com.jzg.jcptadmin.viewinterface.CheckVinAccidentInterface;
import com.jzg.jcptadmin.viewinterface.OperationEvaluationInterface;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.tbruyelle.rxpermissions.Permission;
import com.tbruyelle.rxpermissions.RxPermissions;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.honorato.multistatetogglebutton.MultiStateToggleButton;
import org.honorato.multistatetogglebutton.ToggleButton;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import butterknife.Bind;
import butterknife.BindString;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.pedant.SweetAlert.SweetAlertDialog;
import rx.functions.Action0;
import rx.functions.Action1;

/**
 * 操作中评估界面
 * EvaluationActivity
 *
 * @author sunbl
 *         created at 2016/1/21 16:09
 */
public class EvaluationActivity extends BaseActivity implements OperationEvaluationInterface, View.OnClickListener, CheckVinAccidentInterface {
    @Bind(R.id.title_content)
    TextView inputTopText;
    @Bind(R.id.tv_vin1)
    TextView tvMvin;
    @Bind(R.id.tv_lianxiren)
    TextView tvLianxiren;
    @Bind(R.id.tv_mlianxiren)
    TextView tvMlianxiren;
    @Bind(R.id.tv_phone)
    TextView tvPhone;
    @Bind(R.id.tv_mphone)
    TextView tvMphone;
    @Bind(R.id.tv_chengjiaojia)
    TextView chengjiaojia;
    @Bind(R.id.yuan)
    TextView yuan;
    @Bind(R.id.brand_title)
    TextView brandTitle;
    @Bind(R.id.brand_content)
    MarqueeText brand_content;
    @Bind(R.id.brand_layout)
    LinearLayout brandLayout;
    @Bind(R.id.card_date_content)
    TextView card_date_content;
    @Bind(R.id.card_date_layout)
    RelativeLayout cardDateLayout;
    @Bind(R.id.mileage_content)
    EditText mileage_content;
    @Bind(R.id.km)
    TextView km;
    @Bind(R.id.rl_mileage)
    RelativeLayout rlMileage;
    @Bind(R.id.area_content)
    TextView area_content;
    @Bind(R.id.area_layout)
    RelativeLayout areaLayout;
    @Bind(R.id.beizhu)
    TextView beizhu;
    @Bind(R.id.car_beizhu_text_show)
    TextView carBeizhuTextShow;
    @Bind(R.id.mstb_multi_id)
    MultiStateToggleButton mstbMultiId;
    @Bind(R.id.fl_guzhi)
    FrameLayout flGuzhi;
    @Bind(R.id.tv_changshangzhidao)
    TextView tvChangshangzhidao;
    @Bind(R.id.ll_changshangzhidao)
    RelativeLayout llChangshangzhidao;
    @Bind(R.id.tv_ranliao)
    EditText tvRanliao;
    @Bind(R.id.rl_ranliao)
    RelativeLayout rlRanliao;
    @Bind(R.id.tv_pailiang)
    EditText tvPailiang;
    @Bind(R.id.rl_pailiang)
    RelativeLayout rlPailiang;
    @Bind(R.id.tv_cartype)
    TextView tvCartype;
    @Bind(R.id.rl_cartype)
    RelativeLayout rlCartype;
    @Bind(R.id.tv_biansuqi)
    EditText tvBiansuqi;
    @Bind(R.id.rl_biansuqi)
    RelativeLayout rlBiansuqi;
    @Bind(R.id.tv_people)
    EditText tvPeople;
    @Bind(R.id.rl_people)
    RelativeLayout rlPeople;
    @Bind(R.id.tv_chuchangdata)
    TextView tvChuchangdata;
    @Bind(R.id.rl_chuchangdata)
    RelativeLayout rlChuchangdata;
    @Bind(R.id.tv_pinpaixh)
    EditText tvPinpaixh;
    @Bind(R.id.rl_pinpaixh)
    RelativeLayout rlPinpaixh;
    @Bind(R.id.tv_carnum)
    EditText tvCarnum;
    @Bind(R.id.rl_carnum)
    RelativeLayout rlCarnum;
    @Bind(R.id.tv_shiyongxz)
    TextView tvShiyongxz;
    @Bind(R.id.rl_sihyongxz)
    RelativeLayout rlSihyongxz;
    @Bind(R.id.tv_carcolor)
    TextView tvCarcolor;
    @Bind(R.id.rl_carcolor)
    RelativeLayout rlCarcolor;
    @Bind(R.id.tv_fdjnum)
    EditText tvFdjnum;
    @Bind(R.id.rl_fdjnum)
    RelativeLayout rlFdjnum;
    @Bind(R.id.convenientBanner)
    ConvenientBanner convenientBanner;
    @Bind(R.id.tv_fadan)
    TextView tvFadan;
    @Bind(R.id.tv_fadanphone)
    TextView tvFadanphone;
    @Bind(R.id.chengjiaojia_show)
    TextView chengjiaojiaShow;
    @Bind(R.id.wanyuan)
    TextView wanyuan;
    @Bind(R.id.ranliao)
    TextView ranliao;
    @Bind(R.id.sheng)
    TextView sheng;
    @Bind(R.id.biansuqi)
    TextView biansuqi;
    @Bind(R.id.pinpaixinghao)
    TextView pinpaixinghao;
    @Bind(R.id.tv_fadongji)
    TextView tvFadongji;
    @Bind(R.id.car_beizhu_layout)
    RelativeLayout carBeizhuLayout;
    @Bind(R.id.editText)
    EditText et_Mvin;
    @Bind(R.id.iv_jisudai)
    ImageView ivJisudai;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.tv_jigou)
    TextView tvJigou;
    @Bind(R.id.iv_call)
    ImageView ivCall;
    @Bind(R.id.pic_item)
    ImageView picItem;
    //品牌
    private Make make;

    //车型
    private Style style;

    //省
    private Province province;

    //市
    private City city;
    private int mYear;
    public int mMonth;
    public CarDetails details;
    int carTypeId;//车辆类型id
    //选择信息广播接收器
    private SelectInfoReceiver selectInfoReceiver;
    private OperationEvaluationPresenter operationEvaluationPresenter;
    private String MakeId;
    private String ModelId;
    private String StyleID;
    private String MaxYEAR;
    private String MinYEAR;
    private String CityID;
    private String ProvinceID;
    private FragmentTabAdapter mFragmentTabAdapter;// Fragment试图切换控制器
    private List<Fragment> mFragments;// 所有Fragment页
    private FragmentTransaction ft;
    private TextView editText1;//车商收车价
    private TextView editText2;//鉴定结果
    private TextView editText3;//车商售车价
    private SimpleDateFormat mFormatterMouth = new SimpleDateFormat("yyyy-MM");
    private int currentYear;
    private int currentMonth;
    // private SimpleDateFormat mFormatterData = new SimpleDateFormat("yyyy-MM-dd");
    private static final int PERMISSION_CALL = 1;
    private RxPermissions rxPermissions;
    private UpDataResult upDataResult;

    private CheckVinPrsenter checkVinPresenter;

    //提交参数，带入预览报告
    private Map<String, String> submitParams;

    @BindString(R.string.accident_tip)
    String accidentTip;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_evaluation);
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        rxPermissions = RxPermissions.getInstance(this);
        rxPermissions.setLogging(true);
        ToastDialog();
        callPhone();
        inputTopText.setText("任务评估");
        tvRight.setText("提交");
        details = getIntent().getParcelableExtra("details");
        upDataResult = details.getEvaluateResult();
        operationEvaluationPresenter = new OperationEvaluationPresenter(DataManager.getInstance());
        operationEvaluationPresenter.attachView(this);
        checkVinPresenter = new CheckVinPrsenter(DataManager.getInstance());
        checkVinPresenter.attachView(this);
        //注册接受车辆选择和城市选择的广播接收器
        selectInfoReceiver = new SelectInfoReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction(Constant.CAR_SELECT_BROADCAST);
        filter.addAction(Constant.CITY_SELECT_BROADCAST);
        LocalBroadcastManager.getInstance(this).registerReceiver(selectInfoReceiver, filter);
        getCurrentDate();
        initVin();
        initView();
        initData();
        tvFdjnum.addTextChangedListener(new TextWatcher() {
                                            String tmp = "";
                                            String digits = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`¬!\"£$^*()~=#{}[];\\':,./?/*-_+\"[`~!@^*()+=|{}:;,\\\\[\\\\].?~！@#￥%%……&amp;*（）——+|{}" +
                                                    "【】‘；：”“’。，、？|-]\", \"\"&lt;>@&amp;!\"#$ %&amp;' ()*+, -./:; &lt; = ?@ [\\ ] ^ _`{ | }~  ¡¢£¤ ¥¦§¨© ª« ¬\u00AD ® ¯°± ²³´ µ ¶·¸ ¹º »" +
                                                    "        ¼½ ¾¿ ÀÁ ÂÃ ÄÅ Æ ÇÈÉ Ê ËÌ ÍÎ Ï Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ Ā ā Ă ă Ą ą Ć ć Ĉ" +
                                                    "        ĉ Ċ ċ Č č Ď ď Đ đ Ē ē Ĕ ĕ Ė ė Ę ę Ě ěĜ ĝ Ğ ğ Ġ ġ Ģ ģ Ĥ ĥ Ħ ħ Ĩ ĩ Ī ī Ĭ ĭ Įį İ ı Ĳ ĳ Ĵ ĵ Ķ ķ ĸ Ĺ ĺ Ļ ļ Ľ ľ Ŀ ŀ Łł Ń ń Ņ ņ Ň ň ŉ Ŋ ŋ Ō ō Ŏ ŏ Ő ő Œ œ Ŕ" +
                                                    "        ŕ Ŗ ŗ Ř ř Ś ś Ŝ ŝ Ş ş Š š Ţ ţ Ť ť Ŧ ŧŨ ũ Ū ū Ŭ ŭ Ů ů Ű ű Ų ų Ŵ ŵ Ŷ ŷ Ÿ Ź ź Ż ż Ž ž";

                                            @Override
                                            public void onTextChanged(CharSequence s, int start, int before, int count) {
                                            }

                                            @Override
                                            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                                                tmp = s.toString();
                                            }

                                            @Override
                                            public void afterTextChanged(Editable s) {

                                                String str = s.toString();
                                                if (str.equals(tmp)) {
                                                    return;
                                                }

                                                StringBuffer sb = new StringBuffer();
                                                for (int i = 0; i < str.length(); i++) {
                                                    if (digits.indexOf(str.charAt(i)) >= 0) {
                                                        sb.append(str.charAt(i));
                                                    }
                                                }
                                                tmp = sb.toString();
                                                tvFdjnum.setText(tmp);
                                                //光标放最后
                                                Editable etext = tvFdjnum.getText();
                                                Selection.setSelection(etext, etext.length());
                                            }
                                        }
        );
    }

    private void ToastDialog() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(400);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if ("1".equals(details.getAlreadyValuation())) {
                            CommonUtil.showSingleChoiceDialog(EvaluationActivity.this, Constant.VIN_REPETITION);
                        }
                    }
                });
            }
        }).start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (selectInfoReceiver != null) {
            LocalBroadcastManager.getInstance(this).unregisterReceiver(selectInfoReceiver);
        }
        EventBus.getDefault().unregister(this);
        ACache.get(this).remove(details.getCarId());
    }

    private void initVin() {
        et_Mvin.setKeyListener(new MyNumberKeyListener());
        et_Mvin.setTransformationMethod(new InputLowerToUpper());
    }

    private void getCurrentDate() {
        Calendar c = Calendar.getInstance();
        currentYear = c.get(Calendar.YEAR);
        currentMonth = c.get(Calendar.MONTH) + 1;
    }

    /**
     * 判定输入汉字
     *
     * @param c
     * @return
     */
    public boolean isChinese(char c) {
        Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
        if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
            return true;
        }
        return false;
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    /**
     * 检测String是否全是中文
     *
     * @param name
     * @return
     */
    public boolean checkNameChese(String name) {
        boolean res = true;
        char[] cTemp = name.toCharArray();
        for (int i = 0; i < name.length(); i++) {
            if (!isChinese(cTemp[i])) {
                res = false;
                break;
            }
        }
        return res;
    }

    private void initView() {
        //线上18张 显示维保查询
        findViewById(R.id.ivSplit).setVisibility(View.VISIBLE);
        findViewById(R.id.tvSubtitle).setVisibility(View.VISIBLE);
        if (TextUtils.isEmpty(details.getVideoPath())) {
            picItem.setVisibility(View.INVISIBLE);
        } else {
            picItem.setVisibility(View.VISIBLE);
        }
//        ivCall.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (TextUtils.isEmpty(details.getTasktel())) {
//                    MyToast.showShort("电话号码不能为空");
//                } else {
//                    callPhone();
//                }
//            }
//        });
//        callPhone();//申请权限

//        if(details!=null&&!TextUtils.isEmpty(details.getIsNewEighteen())&&"1".equals(details.getIsNewEighteen())){
//            rlMileage.setVisibility(View.GONE);
//        }else{
//            rlMileage.setVisibility(View.VISIBLE);
//        }

        rlMileage.setVisibility(View.VISIBLE);
        tvPinpaixh.setTransformationMethod(new InputLowerToUpper());//小写转换成大写
        tvFdjnum.setTransformationMethod(new InputLowerToUpper());
        tvCarnum.setTransformationMethod(new InputLowerToUpper());
        ViewGroup.LayoutParams params = convenientBanner.getLayoutParams();
        params.width = RadioGroup.LayoutParams.MATCH_PARENT;
        params.height = ScreenUtils.getScreenWidth(this) * 9 / 16;
        convenientBanner.setLayoutParams(params);
        final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH) + 1;
        MakeId = details.getMakeId();
        ModelId = details.getModelId();
        StyleID = details.getStyleId();
        MaxYEAR = details.getMaxYEAR();
        MinYEAR = details.getLowYear();
        CityID = details.getCityId();
        ProvinceID = details.getProvinceId();

        mFragments = new ArrayList<Fragment>();
        mFragments.add(new SpotPriceFragment());
        mFragments.add(new HistoricalPriceFragment());
        mFragmentTabAdapter = new FragmentTabAdapter(mFragments, this,
                0);
        ft = getSupportFragmentManager()
                .beginTransaction();
        ft.add(R.id.fl_guzhi, mFragments.get(0));
        ft.commit();
        mstbMultiId.setElements(R.array.spotprice, 0);
        mstbMultiId.setColorRes(R.color.btn_blue, R.color.white);
        mstbMultiId.setOnValueChangedListener(new ToggleButton.OnValueChangedListener() {
            @Override
            public void onValueChanged(int value) {
                mFragmentTabAdapter.settingFragment(value, R.id.fl_guzhi);
                if (value == 1) {
                    hideSoft();
                }
            }

        });

        if (!TextUtils.isEmpty(details.getProductTypeImage())) {
            ImageLoader.getInstance().displayImage(details.getProductTypeImage(), ivJisudai, appContext.options);
        }

        // getFragmentManager().findFragmentByTag()
    }

    private void initData() {
        if (details != null) {
//            tvMvin.setText("VIN码:" + details.getVin());
            et_Mvin.setText(details.getVin());//设置Vin码
            et_Mvin.setSelection(et_Mvin.length());//光标到最后一行
            chengjiaojia.setText("成交价: " + details.getBusinessPrice() + "万元");
            brand_content.setText(details.getFullName());
//            if (TextUtils.isEmpty(details.getRegDateYear()) || TextUtils.isEmpty(details.getRegDateMonth())) {
//                card_date_content.setText(details.getRegDateYear() + "" + details.getRegDateMonth());
//            } else {
//                card_date_content.setText(details.getRegDateYear() + "-" + details.getRegDateMonth());
//            }

            //  mileage_content.setText(details.getMileage());
            if (details.getProvinceName().equals(details.getCityName())) {
                area_content.setText(details.getProvinceName());
            } else {
                area_content.setText(details.getProvinceName() + " " + details.getCityName());
            }
            tvChangshangzhidao.setText(details.getManufacturerPrice());//厂商指导价
            tvRanliao.setText(details.getFuel().trim());//燃料
            tvPailiang.setText(details.getEngine_Exhaust());//排量
            tvCartype.setText(details.getCarTypeName());//车辆类型
            try {
                carTypeId = Integer.parseInt(details.getCarTypeID());
            } catch (Exception e) {
                e.printStackTrace();
            }
            tvPinpaixh.setText(details.getRecordBrand());//品牌型号
            tvBiansuqi.setText(details.getTransmissionType());//变速器类型
            tvPeople.setText(details.getSeating());//额定载客
            tvChuchangdata.setText(details.getProductionTime());//登记日期
            tvCarnum.setText(details.getCarLicense());//车牌号码
            tvShiyongxz.setText(details.getServiceName().trim());//使用性质
            tvCarcolor.setText(details.getColorName());//颜色
            tvFdjnum.setText(details.getEngineNum());//发动机号
            tvFadan.setText("发单人: " + details.getTaskOwnerName());
            tvFadanphone.setText("发单人手机: " + details.getTasktel());
            if ("1".equals(details.getShowSourceName())) { //是否显示机构名称 1 显示 0不显示
                tvJigou.setVisibility(View.VISIBLE);
                tvJigou.setText("机构名称: " + details.getSourceName());
            } else {
                tvJigou.setVisibility(View.GONE);
                tvJigou.setText("");
            }


            if (!TextUtils.isEmpty(details.getRegDateYear())) {
                card_date_content.setText(details.getRecordDate());//上牌时间
            }
            if (!TextUtils.isEmpty(details.getMileage())) {
                mileage_content.setText(details.getMileage());//行驶里程
            }


//        carBeizhuTextShow.setText(details.getDes());//备注信息
//            if (details.getIsShowPrice().equals("0")) {
//                isshowPrice.setVisibility(View.GONE);
//            } else {
//            String[] price = details.getAppraise().split("\\.");
//            if (price.length > 1) {
//                if (price[1].length() > 2) {
//                    String price1 = details.getAppraise().substring(0, details.getAppraise().length() - 2);
//                    pricePinggu.setText(price1 + "万元");
//                } else {
//                    pricePinggu.setText(details.getAppraise() + "万元");
//                }
//            } else {
//                pricePinggu.setText(details.getAppraise() + "万元");
//            }

                /*String str = details.getAppraise();
                BigDecimal bd = new BigDecimal(Double.parseDouble(str));
                pricePinggu.setText(bd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "万元");*/


        }

        setPicAdapter();


    }

    private void setPicAdapter() {
        convenientBanner.setPages(
                new CBViewHolderCreator<NetworkImageHolderView>() {
                    @Override
                    public NetworkImageHolderView createHolder() {
                        return new NetworkImageHolderView();
                    }
                }, details.getCarPicList());

        convenientBanner.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(int position) {//查看大图
                Intent intent = new Intent(EvaluationActivity.this, PhotoForNetActivity.class);
                intent.putExtra("piclists", details);
                intent.putExtra("position", position);
                intent.putExtra("isZonghe", true);
                startActivity(intent);
            }
        });
    }

    @Override
    public void checkVinSucc(CheckVinBean suc) {
        if ("1".equals(suc.getIsAccident())) {
            dismissDialog();
            String title = "";
            String confirmText = "返回修改";
            String cancelText = "继续提交";
            SweetAlertDialog sweetDialog = new SweetAlertDialog(EvaluationActivity.this);
            SweetAlertDialog.OnSweetClickListener confirmListener = new SweetAlertDialog.OnSweetClickListener() {
                @Override
                public void onClick(SweetAlertDialog sweetAlertDialog) {
                    sweetAlertDialog.dismiss();

                }
            };
            SweetAlertDialog.OnSweetClickListener cancelListener = new SweetAlertDialog.OnSweetClickListener() {
                @Override
                public void onClick(SweetAlertDialog sweetAlertDialog) {
//                    sweetAlertDialog.dismiss();
//                    showDialog();
//                    operationEvaluationPresenter.OperationEvaluationData();
                    jumpToPreviewReport();//跳到预览报告页面
                }
            };

            if (!TextUtils.isEmpty(title)) {
                sweetDialog.setTitleText(title);
            }
            if (!TextUtils.isEmpty(accidentTip)) {
                sweetDialog.setContentText(accidentTip);
            }
            if (!TextUtils.isEmpty(confirmText)) {
                sweetDialog.setConfirmText(confirmText);

                sweetDialog.setConfirmClickListener(confirmListener);
            }
            if (!TextUtils.isEmpty(cancelText)) {
                sweetDialog.setCancelText(cancelText);
                sweetDialog.setCancelClickListener(cancelListener);
            }
            sweetDialog.show();

        } else {
//            operationEvaluationPresenter.OperationEvaluationData();
            jumpToPreviewReport();//跳到预览报告页面
        }
    }

    @Override
    public void checkVinFail(String fail) {
//        operationEvaluationPresenter.OperationEvaluationData();
        jumpToPreviewReport();//跳到预览报告页面
    }

    @Override
    public Map<String, String> getcheckVinParams() {

        //        Vin=LH17CKKFXAH144371&UserId=3
        Map<String, String> params = new HashMap<String, String>();
        params.put("UserId", "3");
        params.put("tokenid", "6");
        params.put("Vin", et_Mvin.getText().toString().trim().toUpperCase());
//        params.put("Vin", "LH17CKKFXAH144371");
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));

        return params;
    }


    class NetworkImageHolderView implements Holder<CarDetails.CarPicListEntity> {
        private ImageView imageView;
        private TextView title;

        @Override
        public View createView(Context context) {
            //你可以通过layout文件来创建，也可以像我一样用代码创建，不一定是Image，任何控件都可以进行翻页
            View view = LayoutInflater.from(context).inflate(R.layout.taskdetail_photo, null);
            imageView = (ImageView) view.findViewById(R.id.photo_img);
            title = (TextView) view.findViewById(R.id.title);
            return view;
        }

        @Override
        public void UpdateUI(Context context, int position, CarDetails.CarPicListEntity data) {
            int tag = position + 1;
            title.setText(data.getItemName18() + "(" + tag + "/" + details.getCarPicList().size() + ")");
            ImageLoader.getInstance().displayImage
                    (data.getPath(), imageView, appContext.options);
        }
    }

    @Override
    public void goBack(View v) {
        if (editText1 != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editText1.getWindowToken(), 0);
        }
        ACache.get(this).remove(details.getCarId());
        super.goBack(v);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        if (editText1 != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editText1.getWindowToken(), 0);
        }
        ACache.get(this).remove(details.getCarId());
        finish();
    }

    @OnClick({R.id.tvSubtitle, R.id.rl_cartype, R.id.tv_right, R.id.brand_layout, R.id.card_date_layout, R.id.rl_mileage, R.id.area_layout,
            R.id.pic_item, R.id.rl_ranliao, R.id.rl_chuchangdata, R.id.rl_sihyongxz,
            R.id.rl_carcolor, R.id.rl_biansuqi})
    public void onClick(View view) {
        if (view.getId() == R.id.tvSubtitle) {
            getRepairLog();
        } else if (view.getId() == R.id.brand_layout) {
            //ActivityHelp.startActivity(this, BrandActivity.class);
            //MODYBY LZJ
            Intent intent = new Intent(this,PlateTypeActivity.class);
            intent.putExtra("details",details);
            intent.putExtra("vin",details.getVin());
            intent.putExtra("path",details.getCarPicList().get(3).getPath());
            intent.putExtra("bigPath",details.getCarPicList().get(3).getPathBig());
            startActivity(intent);
            //aaaa1111
        } else if (view.getId() == R.id.pic_item) {
            Intent intent = new Intent();
            intent.setClass(this, PlayVideoActiviy.class);
            intent.putExtra(PlayVideoActiviy.KEY_FILE_PATH, details.getVideoPath());
            startActivity(intent);
        } else {
            if (TextUtils.isEmpty(brand_content.getText().toString())) {
                Toast.makeText(this, "请先选择品牌车型！", Toast.LENGTH_SHORT).show();
                return;
            }
            switch (view.getId()) {
                case R.id.tv_right:
                    submitData();//提交

                    break;
                case R.id.card_date_layout://登记日期
                    choosDate(Constant.TIME_SHANGPAI);
                    // chooseTime(Constant.TIME_SHANGPAI);
                    break;
                case R.id.rl_mileage://行驶里程
                    //选择行驶里程
                    //ActivityHelp.startCheckInputActivity(this, Constant.MEILEARE, "行驶里程", "请填写行驶公里(单位：公里)", 6, 6, mileage_content.getText().toString());
                    break;
                case R.id.area_layout://上牌地区
                    Intent areaIntent = new Intent(this, AreaActivity.class);
                    areaIntent.putExtra(Constant.KEY_TITLE, "上牌地区");
                    startActivity(areaIntent);
                    break;
                case R.id.rl_ranliao:
                    //TODO 选择燃料
                    //chooseParam("请选择燃料",Constant.REQ_CODE_CHOOSE_RANLIAO,Constant.SHIYONGRANLIAO);
                    break;
                case R.id.rl_sihyongxz:
                    chooseParam("选择使用性质", Constant.REQ_CODE_SHIYONG_XZ, Constant.SHIYONGXINGZHI);
                    break;
                case R.id.rl_carcolor:
                    chooseParam("选择车身颜色", Constant.REQ_CODE_CAR_COLOR, Constant.CAR_COLORS);
                    break;
                case R.id.rl_biansuqi:
                    //TODO 选择变速器
                    break;
                case R.id.rl_chuchangdata://出厂日期
                    //  choosDate(Constant.TIME_CHUCHANG);
                    chooseTime(Constant.TIME_CHUCHANG);
                    break;
//                case R.id.iv_call://打电话
//
//                    break;
                case R.id.rl_cartype:
                    chooseParam("选择车辆类型", Constant.REQ_CODE_CAR_TYPE, Constant.CAR_TYPE);
                    break;
                case R.id.rl_people:
                    String[] passnum = new String[100];
                    for (int i = 0; i < 100; i++) {
                        passnum[i] = i + "";
                    }
                    chooseParam("选择载客人数", Constant.REQ_CODE_PASSER_NUM, passnum);
                    break;
                default:
                    break;
            }
        }
    }

    private void getRepairLog() {
        Map<String, String> params = new HashMap<String, String>();
        params.put("taskID", details.getCarId());
        params.put("userID", appContext.getUser().getUserId() + "");
        params.put("vin", et_Mvin.getText().toString().toUpperCase());
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        showDialog();
        operationEvaluationPresenter.getRepairLog(params);
    }

    @Override
    public void getRepairSuccess(RepairBean repairBean) {
        dismissDialog();
        switch (repairBean.getData().getRepairLogStatus()) {
            // 0 ：查询中
            case 0:
                MyToast.showLong("维保记录正在查询中");
                break;
            // 1 ：查询成功
            case 1:
                Intent intent = new Intent(this, WebViewActivity.class);
                intent.putExtra("path", repairBean.getData().getRepairLogUrl());
                intent.putExtra("title", "维保记录");
                startActivity(intent);
                break;
            // 2 ：暂无报告
            case 2:
                MyToast.showLong("查询无结果");
                break;
        }
    }

    private void jumpToPreviewReport() {
        Intent intent = new Intent(this, PreviewReportActivity.class);
        getEvaluationParams();
        intent.putExtra("submitParams", (Serializable) submitParams);
        intent.putExtra("brandModel", brand_content.getText().toString());
        intent.putExtra("service", tvShiyongxz.getText().toString());
        intent.putExtra("carColor", tvCarcolor.getText().toString());
        intent.putExtra("area_content", area_content.getText().toString());
        intent.putExtra("cartype", tvCartype.getText().toString());
        intent.putExtra("details", details);
        startActivity(intent);
    }

    private void callPhone() {
        RxView.clicks(findViewById(R.id.iv_call))
                .compose(rxPermissions.ensureEach(Manifest.permission.CALL_PHONE))
                .subscribe(new Action1<Permission>() {
                               @Override
                               public void call(Permission permission) {
                                   if (permission.granted) {
                                       new SweetAlertDialog(EvaluationActivity.this, SweetAlertDialog.WARNING_TYPE)
                                               .setTitleText("提示")
                                               .setContentText(details.getTasktel())
                                               .setConfirmText("呼叫").setCancelText("取消")
                                               .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                                                   @Override
                                                   public void onClick(SweetAlertDialog sDialog) {
                                                       sDialog.dismissWithAnimation();
                                                       try {
                                                           Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + details.getTasktel()));
                                                           startActivity(intent);
                                                       } catch (Exception e) {
                                                           e.printStackTrace();
                                                           MyToast.showShort("拨打电话授权被拒");
                                                       }
                                                   }
                                               }).show();
                                   } else if (permission.shouldShowRequestPermissionRationale) {
                                       MyToast.showShort("拨打电话授权被拒");
                                       // Denied permission without ask never again
                                   } else {

                                       MyToast.showShort("拨打电话授权被拒");
                                   }
                               }
                           },
                        new Action1<Throwable>() {
                            @Override
                            public void call(Throwable t) {
                            }
                        },
                        new Action0() {
                            @Override
                            public void call() {
                            }
                        });

    }

//    @Override
//    public void onRequestPermissionsResult(int requestCode,String[] permissions, int[] grantResults) {
//        MPermissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
//        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
//    }
//    @PermissionDenied(PERMISSION_CALL)
//    public void requestSdcardFailed() {
//        MyToast.showShort("拨打电话授权被拒!");
//    }
//
//    @PermissionGrant(PERMISSION_CALL)
//    public void requestCallSuccess() {
//   new SweetAlertDialog(EvaluationActivity.this, SweetAlertDialog.WARNING_TYPE)
//    .setTitleText("提示")
//    .setContentText(details.getTasktel())
//            .setConfirmText("呼叫").setCancelText("取消")
//    .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
//        @Override
//        public void onClick(SweetAlertDialog sDialog) {
////                                            Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + details.getTasktel()));
////                                            startActivity(intent);
////                                            sDialog.dismissWithAnimation();
//        }
//    }).show();
//    }


    private void chooseParam(String title, int requestCode, String[] items) {
        Intent intent = new Intent(this, SingleChooseActivity.class);
        intent.putExtra(Constant.KEY_ARR, items);
        intent.putExtra(Constant.KEY_TITLE, title);
        startActivityForResult(intent, requestCode);
    }

    private void submitData() {
        if (checkParams()) {
//            showDialog();
            // operationPresenter.OperationData("pinggu", getIntent().getStringExtra("id"), "", price.getText().toString(), result.getText().toString(), appContext.getUser().getUserId() + "");
//            operationEvaluationPresenter.OperationEvaluationData();
            checkVin();
        }

    }

    private void checkVin() {
        if (details.getVin() != null && !details.getVin().equals(et_Mvin.getText().toString().trim())) {
            checkVinPresenter.checkvin();
        } else {
            jumpToPreviewReport();//跳到预览报告页面
//            operationEvaluationPresenter.OperationEvaluationData();
        }
    }

    /**
     * 校验参数
     *
     * @return
     */
    private boolean checkParams() {
        if (et_Mvin.getText().toString().length() < 17) {
            Toast.makeText(this, "请输入正确的VIN", Toast.LENGTH_SHORT).show();
            return false;
        }
        if (!checkText(brand_content.getText().toString(), "车型")
                || !checkText(tvChangshangzhidao.getText().toString(), "厂商指导价")
                || !checkText(tvRanliao.getText().toString(), "燃料")
                || !checkNum(tvPailiang, 0, 9999, "排量")//tvPeople
                || !checkText(tvCartype.getText().toString(), "车辆类型")
                || !checkText(tvBiansuqi.getText().toString(), "变速器")
                || !checkNum(tvPeople, 1, 99, "载客人数")
                || !checkText(card_date_content.getText().toString(), "登记日期")
                || !checkText(tvChuchangdata.getText().toString(), "出厂日期")
                || !checkTextUpperCase(tvPinpaixh, "品牌型号")
                || !checkoutcarNum()
                || !checkText(tvShiyongxz.getText().toString(), "使用性质")
                || !checkText(tvCarcolor.getText().toString(), "车身颜色")
                || !checkTextUpperCase(tvFdjnum, "发动机号")
                || !checkText(area_content.getText().toString(), "上牌地区")
                || !checkNum(mileage_content, 100, 9999999, "表显里程")
                ) {
            return false;
        }

        if (editText1 != null && !checkDoubleNum(editText1, 0.01, -1, "车商收车价格")) {
            return false;
        }
        if (editText3 != null && !checkDoubleNum(editText3, 0.01, -1, "车商售车价格")) {
            return false;
        }

        if (editText2 != null && TextUtils.isEmpty(editText2.getText().toString().trim())) {
            MyToast.showLong("请输入鉴定结果");
            return false;
        }

        if (upDataResult == null || upDataResult.getSelectedItem().size() == 0) {
            MyToast.showLong("请输入鉴定结果");
            return false;
        }
        if (Double.parseDouble(editText1.getText().toString().trim()) >= Double.parseDouble(editText3.getText().toString().trim())) {
            MyToast.showLong("售车价必须大于收车价");
            return false;
        }
        try {
            String str = card_date_content.getText().toString().trim();
            Long mdengji = mFormatterMouth.parse(str.substring(0, str.length() - 3)).getTime();//登记日期
            Long mchuchang = mFormatterMouth.parse(tvChuchangdata.getText().toString().trim()).getTime();//出厂日期
            if (mchuchang > mdengji) {
                Toast.makeText(EvaluationActivity.this, "登记日期不能小于出厂日期", Toast.LENGTH_SHORT).show();
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(EvaluationActivity.this, "登记日期不能小于出厂日期", Toast.LENGTH_SHORT).show();
            return false;
        }

        return true;
    }

    private boolean checkoutcarNum() {
        if (!tvCarnum.getText().toString().equals("无")) {
            tvCarnum.setText(tvCarnum.getText().toString().toUpperCase());
            if (!isChePai(tvCarnum.getText().toString())) {
                MyToast.showLong("请输入正确的车牌号");
                return false;
            }
        }
        return true;
    }

    /**
     * @param editText 输入的控件
     * @param num      限制的最小数
     * @param name
     * @return
     */
    private boolean checkNum(TextView editText, int num, int bignum, String name) {

//        if(editText.getVisibility()==View.GONE){
//            return true;
//        }
        try {
            if (TextUtils.isEmpty(editText.getText().toString().trim())) {
                MyToast.showLong(name + "不能为空");
                return false;
            }
            Double number = Double.parseDouble(editText.getText().toString().trim());
            if (number < num) {
                MyToast.showLong(name + "不能小于" + num);
                return false;
            }
            if (bignum != -1) {
                if (number > bignum) {
                    MyToast.showLong(name + "不能大于" + bignum);
                    return false;
                }
            }

        } catch (Exception e) {
            MyToast.showLong(name + "输入格式错误");
            return false;
        }
        return true;
    }

    /**
     * @param editText
     * @param num      最小数
     * @param bignum   最大数
     * @param name
     * @return
     */
    private boolean checkDoubleNum(TextView editText, Double num, int bignum, String name) {
        try {
            if (TextUtils.isEmpty(editText.getText().toString().trim())) {
                MyToast.showLong(name + "不能为空");
                return false;
            }
            Double number = Double.parseDouble(editText.getText().toString().trim());
            if (number < num) {
                MyToast.showLong(name + "不能小于" + num);
                return false;
            }
            if (bignum != -1) {
                if (number > bignum) {
                    MyToast.showLong(name + "不能大于" + bignum);
                    return false;
                }
            }

        } catch (Exception e) {
            MyToast.showLong(name + "输入格式错误");
            return false;
        }
        return true;
    }

    private boolean checkText(String str, String name) {
        if (TextUtils.isEmpty(str.trim())) {
            MyToast.showLong(name + "不能为空");
            return false;
        }
        return true;
    }

    private boolean checkTextUpperCase(EditText editText, String name) {
        editText.setText(editText.getText().toString().toUpperCase());
        if (TextUtils.isEmpty(editText.getText().toString().trim())) {
            MyToast.showLong(name + "不能为空");
            return false;
        }
        return true;
    }

    /**
     * 校验车牌号
     *
     * @param str
     * @return
     */
    public boolean isChePai(String str) {
        Pattern pattern = Pattern.compile("^[\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z_0-9]{5}$");
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }


    /**
     * 获取评估参数
     *
     * @return
     */
    @Override
    public Map<String, String> getEvaluationParams() {
        submitParams = new HashMap<String, String>();
        submitParams.put("tokenid", "6");
        submitParams.put("type", "pinggu");
        submitParams.put("taskid", details.getCarId());
        if (editText1 != null) {
            submitParams.put("appraiseprice", editText1.getText().toString());//收车价
        }
        if (editText2 != null) {
            submitParams.put("appraisedes", editText2.getText().toString());
        }
        if (editText3 != null) {
            submitParams.put("SalePrice", editText3.getText().toString());
        }

        submitParams.put("userId", appContext.getUser().getUserId() + "");
        submitParams.put("MakeId", MakeId);
        submitParams.put("ModelId", ModelId);
        submitParams.put("StyleId", StyleID);
        submitParams.put("CityId", CityID);
        submitParams.put("RegDate", card_date_content.getText().toString());//登记日期
        submitParams.put("Mileage", mileage_content.getText().toString());///表显里程

        submitParams.put("makeNumber", tvPinpaixh.getText().toString());//品牌型号
        submitParams.put("carLicence", tvCarnum.getText().toString());//车牌号
        submitParams.put("service", Constant.map.get(tvShiyongxz.getText().toString()) + "");//使用性质
        submitParams.put("carColor", Constant.mapcolor.get(tvCarcolor.getText().toString()) + "");//车身颜色
        submitParams.put("engineNum", tvFdjnum.getText().toString());//发动机号
        submitParams.put("mPrice", tvChangshangzhidao.getText().toString());//厂商指导价
        submitParams.put("fuel", tvRanliao.getText().toString());//燃料
        submitParams.put("exhaust", tvPailiang.getText().toString());//排气量
        submitParams.put("carType", carTypeId + "");//车辆类型
        submitParams.put("tranType", tvBiansuqi.getText().toString());//变速器
        submitParams.put("seating", tvPeople.getText().toString());//载客人数
        submitParams.put("productionTime", tvChuchangdata.getText().toString());//出厂日期
        submitParams.put("VIN", et_Mvin.getText().toString().toUpperCase());//vin
        submitParams.put("isConfirmSubmit", "1");//vin
        submitParams.put("EvaluateResult", new Gson().toJson(upDataResult));//vin
        submitParams.put("isNewEighteen", details.getIsNewEighteen());//1代表新18张  其他不管

        Map<String, Object> maps = new HashMap<>();
        maps.putAll(submitParams);
        submitParams.put("sign", MD5Utils.getMD5Sign(maps));
        return submitParams;
    }


    @Override
    public Map<String, String> getCanpeiParams(String styleID) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("tokenid", "6");
        params.put("styleId", styleID);
        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        return params;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) {
            return;
        }
        switch (requestCode) {
            case Constant.TIME_SHANGPAI:
//                int year = data.getIntExtra("year", 2015);
//                int month = data.getIntExtra("month", 1);
//                if(month<10){
//                    card_date_content.setText(year + "-0" + month);
//                }else{
//                    card_date_content.setText(year + "-" + month);
//                }
                String chooseDate = data.getStringExtra("car_Time_MSG");
                card_date_content.setText(chooseDate);
                break;
            case Constant.TIME_CHUCHANG:
                int year = data.getIntExtra("year", 2015);
                int month = data.getIntExtra("month", 1);
                if (month < 10) {
                    tvChuchangdata.setText(year + "-0" + month);
                } else {
                    tvChuchangdata.setText(year + "-" + month);
                }
//                String chooseDate  = data.getStringExtra("car_Time_MSG");
//                tvChuchangdata.setText(chooseDate);
                break;
            case Constant.MEILEARE:
                mileage_content.setText(data.getStringExtra(Constant.ACTIVITY_INPUT));
                break;
            case Constant.REQ_CODE_SHIYONG_XZ:
                tvShiyongxz.setText(data.getStringExtra("result"));
                break;
            case Constant.REQ_CODE_CAR_COLOR:
                tvCarcolor.setText(data.getStringExtra("result"));
                break;
            case Constant.REQ_CODE_CAR_TYPE:

                if (!TextUtils.isEmpty(data.getStringExtra("result"))) {
                    tvCartype.setText(data.getStringExtra("result"));
                    List list = Arrays.asList(Constant.CAR_TYPE);
                    carTypeId = list.indexOf(data.getStringExtra("result")) + 1;
                }
                break;
            case Constant.REQ_CODE_PASSER_NUM:
                tvPeople.setText(data.getStringExtra("result"));
                break;
            default:

                break;
        }
    }

    private void refreshResult(TextView view, String result) {
        view.setText(result);
    }

    @Override
    public void showError(String error) {
        dismissDialog();
        if (TextUtils.isEmpty(error)) {
            MyToast.showLong(Constant.errr_net);
        } else {
            MyToast.showLong(error);
        }
    }

    @Override
    public void showresult(SuccessValuationData result) {
        dismissDialog();
        if (result.getStatus().equals("100")) {
            ACache.get(this).remove(details.getCarId());
            if ("0".equals(result.getAssessResult())) {
                LocalData.isRefresh = true;
                AppManager.getAppManager().finishActivity(FastOnlineCheckActivity1.class);
                //操作成功
                MyToast.showLong("评估成功");
                finish();
                AppManager.getAppManager().finishActivity(FastOnlineCheckActivity1.class);
            } else if ("1".equals(result.getAssessResult())) {
                LocalData.isRefresh = true;
                AppManager.getAppManager().finishActivity(FastOnlineCheckActivity1.class);
                Intent out = new Intent(this, SubmitOutActivity.class);
                Bundle b = new Bundle();
                b.putParcelable("result", result);
                out.putExtras(b);
                startActivity(out);
                finish();
            } else if ("2".equals(result.getAssessResult())) {
                Intent in = new Intent(this, SubmitInActivity.class);
                Bundle b = new Bundle();
                b.putString("buy_money", editText1.getText().toString().trim());//车商收车价格
                b.putString("sale_money", editText3.getText().toString().trim());//车商售车价格
                b.putParcelable("result", result);
                //传递参数
//                SerializableMap map = new SerializableMap();
//                map.setMap(getEvaluationParams());
//                b.putSerializable("map", map);
//                in.putE
//                in.putExtra("map", map);


                in.putExtra("taskid", details.getCarId());
                in.putExtra("appraiseprice", editText1.getText().toString());//收车价
                in.putExtra("appraisedes", editText2.getText().toString());
                in.putExtra("SalePrice", editText3.getText().toString());
                in.putExtra("isConfirmSubmit", 0 + "");//评估误差较大时，是否确认提交 1是 0否
                in.putExtra("userId", appContext.getUser().getUserId() + "");
                in.putExtra("MakeId", MakeId);
                in.putExtra("ModelId", ModelId);
                in.putExtra("StyleId", StyleID);
                in.putExtra("CityId", CityID);
                in.putExtra("RegDate", card_date_content.getText().toString());//登记日期
                in.putExtra("Mileage", mileage_content.getText().toString());///表显里程
                in.putExtra("makeNumber", tvPinpaixh.getText().toString());//品牌型号
                in.putExtra("carLicence", tvCarnum.getText().toString());//车牌号
                in.putExtra("service", Constant.map.get(tvShiyongxz.getText().toString()) + "");//使用性质
                in.putExtra("carColor", Constant.mapcolor.get(tvCarcolor.getText().toString()) + "");//车身颜色
                in.putExtra("engineNum", tvFdjnum.getText().toString());//发动机号
                in.putExtra("mPrice", tvChangshangzhidao.getText().toString());//厂商指导价
                in.putExtra("fuel", tvRanliao.getText().toString());//燃料
                in.putExtra("exhaust", tvPailiang.getText().toString());//排气量
                in.putExtra("carType", carTypeId + "");//车辆类型
                in.putExtra("tranType", tvBiansuqi.getText().toString());//变速器
                in.putExtra("seating", tvPeople.getText().toString());//载客人数
                in.putExtra("productionTime", tvChuchangdata.getText().toString());//出厂日期
                in.putExtra("VIN", et_Mvin.getText().toString().toUpperCase());//vin

                in.putExtras(b);
                startActivity(in);
            }
        } else {
            MyToast.showLong(result.getMsg());
        }
    }

    public static class SerializableMap implements Parcelable {

        private Map<String, String> map;

        public void setMap(Map<String, String> map) {
            this.map = map;
        }

        public Map<String, String> getMap() {
            return map;
        }


        protected SerializableMap(Parcel in) {
        }

        public final static Creator<SerializableMap> CREATOR = new Creator<SerializableMap>() {
            @Override
            public SerializableMap createFromParcel(Parcel in) {
                return new SerializableMap(in);
            }

            @Override
            public SerializableMap[] newArray(int size) {
                return new SerializableMap[size];
            }
        };

        public SerializableMap() {

        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {

        }
    }

    @Override
    public void showCanPei(Canpei result) {
        dismissDialog();
        if (result.getStatus() == 100) {
            tvChangshangzhidao.setText(result.getNowMsrp());//厂商指导价
            tvRanliao.setText(result.getFuel().trim());//燃料
            tvPailiang.setText(result.getExhaustVolume());//排量
            tvCartype.setText(result.getCarType().getCarTypeName());//车辆类型
            carTypeId = result.getCarType().getCarTypeId();
            tvBiansuqi.setText(result.getTransmission());//变速器类型
            tvPeople.setText(result.getSeatNumber());//额定载客
        } else {
            MyToast.showLong(result.getMsg());
        }

    }

    private void choosDate(int requestCode) {
        Intent intent = new Intent(this, SelectDateActivity.class);
        intent.putExtra("Minyear", StringUtils.getYear4String(MinYEAR));
        intent.putExtra("MinMonth", StringUtils.getMonth4String(MinYEAR));
        // intent.putExtra("CurMonth", mMonth);
        intent.putExtra(Constant.KEY_TITLE, "登记日期");
        startActivityForResult(intent, requestCode);
    }

    /**
     * 弹出选择时间,包括年、月
     *
     * @param requestCode
     */
    private void chooseTime(int requestCode) {
        try {

            Intent in = new Intent(this, SheetTimeAty.class);
//            in.putExtra("Maxyear", StringUtils.getYear4String(MaxYEAR));
            in.putExtra("Maxyear", currentYear);
            in.putExtra("Minyear", StringUtils.getYear4String(MinYEAR));
//            in.putExtra("MaxMonth", StringUtils.getMonth4String(MaxYEAR));
            in.putExtra("MaxMonth", currentMonth);
            in.putExtra("MinMonth", StringUtils.getMonth4String(MinYEAR));
            in.putExtra("CurMonth", mMonth);
            in.putExtra(Constant.KEY_TITLE, "请选择出厂日期");
            startActivityForResult(in, requestCode);
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(this, "请重新选择品牌车型！", Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 选择品牌、车系、车型、省、市广播接受
     */
    class SelectInfoReceiver extends BroadcastReceiver {
        public void onReceive(Context context, Intent intent) {
//            Logger.i("enter");
            //城市选择接受数据
            if (intent.getAction().equals(Constant.CITY_SELECT_BROADCAST)) {
//                Logger.i(intent.getParcelableExtra(Constant.CITY).toString());
//                Logger.i(intent.getParcelableExtra(Constant.PROVINCE).toString());
                city = intent.getParcelableExtra(Constant.CITY);
                province = intent.getParcelableExtra(Constant.PROVINCE);

                if (province != null) {
                    if (province.getName() != null && city.getName() != null) {
                        area_content.setText(String.format("%s %s", province.getName(), city.getName()));
                        ProvinceID = province.getId() + "";
                        CityID = city.getId() + "";
                        details.setProvinceId(ProvinceID);
                 /*   if (!isChange) {
                        publishAssignmentData.setProv(province.getName());
                        publishAssignmentData.setCity(city.getName());
                        publishAssignmentData.setProvid(province.getId() + "");
                        publishAssignmentData.setCityId(city.getId() + "");
                    } else {
                        details.setProvinceName(province.getName());
                        details.setCityName(city.getName());
                        details.setCityId(city.getId() + "");
                        details.setProvinceId(province.getId() + "");
                    }*/
                    }
                }
            }
            //品牌、车系、车型接受数据
            else if (intent.getAction().equals(Constant.CAR_SELECT_BROADCAST)) {
                make = intent.getParcelableExtra(Constant.MAKE);
                //对是否有全部选项进行判断，在估值界面是没有全部选项的，如果这里接受到了
                //带全部选项列表发送的广播，则进行一次判断，避免从及时系统查看历史记录并做
                //筛选操作的时候出现数据反显的bug
                if (!make.isMakeAll()) {
                    style = intent.getParcelableExtra(Constant.STYLE);
                }

//                Logger.i(style.toString());
//                Logger.i(intent.getParcelableExtra(Constant.MODEL).toString());
                if (style != null) {
                    brand_content.setText(style.getFullName());
                    MakeId = style.getMakeId() + "";
                    ModelId = style.getModelId() + "";
                    StyleID = style.getId() + "";
                    MaxYEAR = style.getMaxYEAR();
                    MinYEAR = style.getMinYEAR();
                    operationEvaluationPresenter.getCanPei(StyleID);
                    //        if (!isChange) {
//                        publishAssignmentData.setStyleId(style.getId() + "");
//                        publishAssignmentData.setMakeId(style.getMakeId() + "");
//                        publishAssignmentData.setModelId(style.getModelId() + "");
//                        publishAssignmentData.setStyleName(style.getName());
//                        publishAssignmentData.setMakeName(style.getMakeName());
//                        publishAssignmentData.setModeName(style.getModelName());
//                        publishAssignmentData.setFullName(style.getFullName());
                    // publishAssignmentData.setStyle(style);
//                    } else {
//                        details.setStyleId(style.getId() + "");
//                        details.setMakeId(style.getMakeId() + "");
//                        details.setModelId(style.getModelId() + "");
//                        details.setFullName(style.getFullName());
//                    }
                }
                //关闭车型选择相关的Activity by zealjiang
                AppManager.getAppManager().finishActivity(CarDifferenceConfigSelectActivity.class);
                AppManager.getAppManager().finishActivity(BrandActivity.class);
                AppManager.getAppManager().finishActivity(CarTypeSelectActivity.class);
                AppManager.getAppManager().finishActivity(PlateTypeActivity.class);
            }

        }
    }

    public void setEditText(EditText editText1, TextView editText2, EditText editText3) {
        this.editText1 = editText1;
        this.editText2 = editText2;
        this.editText3 = editText3;

    }

    public void hideSoft() {
        if (editText1 != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editText1.getWindowToken(), 0);
        }
    }

    public CarDetails getData() {
        return details;
    }

    @Subscribe(threadMode = ThreadMode.MAIN, priority = 10)
    public void OnEvent(UpDataResult upDataResult) {
        this.upDataResult = upDataResult;
    }

}
